Skip to content

Issue #366: make mask method available to MetaSWAP model class#1871

Open
rleander73 wants to merge 4 commits into
masterfrom
Issue_#366_Add_mask_method_to_MetaSWAP_model
Open

Issue #366: make mask method available to MetaSWAP model class#1871
rleander73 wants to merge 4 commits into
masterfrom
Issue_#366_Add_mask_method_to_MetaSWAP_model

Conversation

@rleander73

@rleander73 rleander73 commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #366

Description

Checklist

  • [*] Links to correct issue
  • [-] Update changelog, if changes affect users
  • [*] PR title starts with Issue #nr, e.g. Issue #737
  • [*] Unit test was added:
  • [*] If feature added: Added/extended example (in docstring)
  • [*] If feature added: Added feature to API documentation
  • [-] If pixi.lock was changed: Ran pixi run generate-sbom and committed changes

@sonarqubecloud

Copy link
Copy Markdown

@rleander73 rleander73 marked this pull request as ready for review June 25, 2026 14:49

@JoerivanEngelen JoerivanEngelen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some comments on the public API, after which we have a very useful method!

# Check that the mask has been applied correctly to each package
for pkgname, pkg in msw_model.items():
if isinstance(pkg, msw.meteo_mapping.PrecipitationMapping):
continue # Skip PrecipitationMapping package for this test

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we skipping the PrecipitationMapping? The actual mappings are derived upon writing, if I recall correctly, so I think these objects should be identical? Or am I missing something?

Comment thread imod/msw/model.py

Parameters
----------
msw_active: MetaSwapActive, dictionary of xr.DataArray

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MetaSwapActive currenlty is a developer utility, not public API.

Adding extra dataclasses to the API adds extra entry barriers for users, which I like to avoid: They need to import additional python objects, which they need to look up in the docs.

The "all" mask usually is an .any(dim="subunit"), so I think we can derive that for the user, I would do something like:

def mask_all_packages(self, mask: GridDataArray):
     ...
     mask_all = mask.any(dim="subunit")
     msw_active = MetaSwapActive(per_subunit=mask, all=mask_all)
     ...

Comment thread imod/msw/model.py
def mask_all_packages(
self,
msw_active: MetaSwapActive,
# ignore_time_purge_empty: bool = False,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this outcommented code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add mask method to MetaSWAP model

3 participants